package com.otojob.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.otojob.entity.Company;
import com.otojob.entity.Job;
import com.otojob.entity.vo.CompanyCertification;
import com.otojob.entity.vo.ReleaseJob;
import com.otojob.mapper.UserMapper;
import com.otojob.service.CompanyService;
import com.otojob.service.JobService;
import com.otojob.service.OssService;
import com.otojob.utils.JwtUtils;
import com.otojob.utils.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.awt.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TingFeng
 * @since 2022-03-18
 */

@RestController
@Api(value = "PublishController", tags = "认证")
@CrossOrigin
@RequestMapping("/publish")
public class PublishController {

    @Autowired
    private CompanyService companyService;
    @Autowired
    private OssService ossService;
    @Resource
    private UserMapper userMapper;
    @Autowired
    private JobService jobService;

    @Resource
    private HttpServletRequest request;


    @ApiOperation("判断是否认证企业")
    @GetMapping("/checkCertification")
    public Results checkCertification(){
        Results results = companyService.checkCertification();
        return results;
    }
    @ApiOperation("查询已发布职位")
    @GetMapping("/findReleasedJob")
    public  Results findReleasedJob(){
        int userId = JwtUtils.getMemberIdByJwtToken(request);
        return jobService.findReleasedJob(userId);
    }

    @ApiOperation("发布职位")
    @PostMapping("/releaseJob")
    public  Results releaseJob(@Valid @RequestBody ReleaseJob releaseJob){
        int userId = JwtUtils.getMemberIdByJwtToken(request);
        return jobService.releaseJob(releaseJob,userId);
    }

  @ApiOperation("上传营业执照")
    @PostMapping("/oss")
    public String oss(MultipartFile file){
        int id = JwtUtils.getMemberIdByJwtToken(request);
        int i = userMapper.findUser(id);
        if(i!=1){
            return "该用户未注册";
        }
        String url = ossService.upLoadPhoto(file, id);
        return url;
    }




}

